package com.kaesun.ufit.tools;

import android.content.Context;
import android.content.SharedPreferences;

public class ConfigData {

	private static final String NAME_PREF = "weight_config";

	public static final String PREF_MODEL_IDX = "model_idx";
	public static final String PREF_MODEL_NO = "model_no";
	public static final String PREF_MODEL_NEO_ID = "model_neo_id";
	public static final String PREF_MODEL_MOMENTUM_MIN = "model_momentum_min";
	public static final String PREF_MODEL_MOMENTUM_MAX = "model_momentum_max";
	public static final String PREF_MODEL_BARBEL_WEIGHT = "model_barbel_weight";
	public static final String PREF_MODEL_BARBEL_COUNT = "model_barbel_count";
	public static final String PREF_MODEL_HALL_GAP = "model_hall_gap";
	public static final String PREF_MODEL_HALL_COUNT = "model_hall_count";

	public static final String PREF_SETUP_PASSWORD = "setup_password";

	public static final String PREF_MOMENTUM_COUNT = "momentum_count";
	public static final String PREF_MOMENTUM_SET = "momentum_set";
	public static final String PREF_ONERM_COUNT = "onerm_count";

	public static final String PREF_SERVICE_SCREENSAVER = "service_screensaver";
	public static final String PREF_SERVICE_LANGUAGE = "service_language";

	public static final String PREF_WIFI_SSID = "wifi_ssid";
	public static final String PREF_WIFI_SECURITY = "wifi_security";
	public static final String PREF_WIFI_PASSWORD = "wifi_password";
	public static final String PREF_WIFI_SERVER = "wifi_server";
	public static final String PREF_WIFI_PORT = "wifi_port";


	public static final int DEF_MODEL_IDX = 0;	//ModelType.IDX_SLP;
	public static final int DEF_MODEL_NO = 1;	// 1 ~
	public static final String DEF_MODEL_NEO_ID = "UF101A1";	// UF101A + 1
	public static final int DEF_MODEL_MOMENTUM_MIN = 40;
	public static final int DEF_MODEL_MOMENTUM_MAX = 50;
	public static final int DEF_MODEL_BARBEL_WEIGHT = 5;
	public static final int DEF_MODEL_BARBEL_COUNT = 16;
	public static final float DEF_MODEL_HALL_GAP = (float)0.016;
	public static final int DEF_MODEL_HALL_COUNT = 60;

	public static final String DEF_SETUP_PASSWORD = "0000";
	public static final String RESET_SETUP_PASSWORD = "52378677678";	// "kaesunsport"

	public static final int DEF_MOMENTUM_COUNT = 5;
	public static final int DEF_MOMENTUM_SET = 1;
	public static final int MIN_ONERM_COUNT = 1;
	public static final int MAX_ONERM_COUNT = 15;
	public static final int DEF_ONERM_COUNT = 15;

	public static final boolean DEF_SERVICE_SCREENSAVER = false;

	public static final int SERVICE_LANGUAGE_KOR = 0;
	public static final int SERVICE_LANGUAGE_ENG = 1;
	public static final int DEF_SERVICE_LANGUAGE = SERVICE_LANGUAGE_KOR;

	public static final int DEF_ZIGBEE_GROUPID = 1000;	// 0x1000 ~ 0xF000
	public static final int DEF_ZIGBEE_ID = 2000;	// 0x2000 ~ 0xFFFE
	public static final int DEF_ZIGBEE_USEDACK = 1;	// used(1), notUsed(0)
	public static final int DEF_ZIGBEE_RETRYCOUNT = 1;	// 1 ~ 32
	public static final int DEF_ZIGBEE_USEDHOP = 0;	// Used(1), RfLevel(2), notUsed(0)
	public static final int DEF_ZIGBEE_HOPDEPTH = 2;	// 2 ~ 8
	public static final int DEF_ZIGBEE_HOPLEVEL = 80;	// 80 ~ 100
	public static final int DEF_ZIGBEE_RFCHANNEL = 5;	// 0 ~ 15

	public static final String DEF_WIFI_SSID = "smart-fit";
	public static final String DEF_WIFI_SECURITY = "WPA2";	// OPEN, WEP, WPA, WPAAES, WPA2AES, WPA2TKIP, WPA2
	public static final String DEF_WIFI_PASSWORD = "kaesun1811";
	public static final String DEF_WIFI_SERVER = "192.168.0.100";
	public static final int DEF_WIFI_PORT = 9001;


	public static void factoryReset(Context context) {
		setPref(context, PREF_MODEL_IDX, DEF_MODEL_IDX);
		setPref(context, PREF_MODEL_NO, DEF_MODEL_NO);
		setPref(context, PREF_MODEL_NEO_ID, DEF_MODEL_NEO_ID);
		setPref(context, PREF_MODEL_MOMENTUM_MIN, DEF_MODEL_MOMENTUM_MIN);
		setPref(context, PREF_MODEL_MOMENTUM_MAX, DEF_MODEL_MOMENTUM_MAX);
		setPref(context, PREF_MODEL_BARBEL_WEIGHT, DEF_MODEL_BARBEL_WEIGHT);
		setPref(context, PREF_MODEL_BARBEL_COUNT, DEF_MODEL_BARBEL_COUNT);
		setPref(context, PREF_MODEL_HALL_GAP, DEF_MODEL_HALL_GAP);
		setPref(context, PREF_MODEL_HALL_COUNT, DEF_MODEL_HALL_COUNT);

		setPref(context, PREF_MOMENTUM_COUNT, DEF_MOMENTUM_COUNT);
		setPref(context, PREF_MOMENTUM_SET, DEF_MOMENTUM_SET);
		setPref(context, PREF_ONERM_COUNT, DEF_ONERM_COUNT);

		setPref(context, PREF_SERVICE_SCREENSAVER, DEF_SERVICE_SCREENSAVER);
		setPref(context, PREF_SERVICE_LANGUAGE, DEF_SERVICE_LANGUAGE);

		setPref(context, PREF_WIFI_SSID, DEF_WIFI_SSID);
		setPref(context, PREF_WIFI_SECURITY, DEF_WIFI_SECURITY);
		setPref(context, PREF_WIFI_PASSWORD, DEF_WIFI_PASSWORD);
		setPref(context, PREF_WIFI_SERVER, DEF_WIFI_SERVER);
		setPref(context, PREF_WIFI_PORT, DEF_WIFI_PORT);
	}

	public static String getPrefString(Context context, String key, String def) {
		return context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).getString(key, def);
	}

	public static int getPrefInteger(Context context, String key, int def) {
		return context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).getInt(key, def);
	}

	public static float getPrefFloat(Context context, String key, float def) {
		return context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).getFloat(key, def);
	}

	public static boolean getPrefBoolean(Context context, String key, boolean def) {
		return context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).getBoolean(key, def);
	}

	public static boolean setPref(Context context, String key, String value) {
		SharedPreferences.Editor edit = context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).edit();
		edit.putString(key, value);

		return edit.commit();
	}

	public static boolean setPref(Context context, String key, int value) {
		SharedPreferences.Editor edit = context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).edit();
		edit.putInt(key, value);

		return edit.commit();
	}

	public static boolean setPref(Context context, String key, float value) {
		SharedPreferences.Editor edit = context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).edit();
		edit.putFloat(key, value);

		return edit.commit();
	}

	public static boolean setPref(Context context, String key, boolean value) {
		SharedPreferences.Editor edit = context.getSharedPreferences(NAME_PREF, Context.MODE_PRIVATE).edit();
		edit.putBoolean(key, value);

		return edit.commit();
	}
}
